package com.mf.dispatcher;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.mf.controller.UserController;


@WebServlet("/ControllerUser/*")
public class ControllerUserDispather extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private String traget;
    public ControllerUserDispather() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String url= request.getRequestURI();
		String myUrl = url.substring(url.lastIndexOf("/")+1);
		response.setContentType("application/json; charset=utf-8"); 
		UserController userController=new UserController();
		PrintWriter out=response.getWriter();
		String jsonString;
		switch(myUrl){
			case "allUser":
				 jsonString=JSON.toJSONString(userController.allUser());
				traget = jsonString;
				out=response.getWriter();
				out.println(traget);
				break;
			case "updateUser":
				
				break;
			case "delUser":
				 jsonString=JSON.toJSONString(userController.delUser(request.getParameter("id")));
				traget = jsonString;
				out=response.getWriter();
				out.println(traget);
				break;
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
